package com.qk.management.controller;

import com.qk.dto.customer.CustomerDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import com.qk.result.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author:zhengbowen
 * @Date: 2025/10/14 16:42
 * @Description: 客户管理控制器
 */
@Slf4j
@RestController
@RequestMapping("/customers")
@RequiredArgsConstructor
public class CustomerController {
    private final CustomerService customerService;

    @PostMapping ("")
    public Result insertCustomer(@RequestBody Customer customer) {
        customerService.insertCustomer(customer);
        return Result.success();
    }

    @PutMapping("")
    public Result updateCustomer(@RequestBody Customer customer) {
        customerService.updateDataById(customer);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectCustomerById(@PathVariable String id) {
        return Result.success(customerService.getById(id));
    }

    @GetMapping("")
    public Result selectCustomersByPage(CustomerDTO customerDTO) {
        return Result.success(customerService.selectCustomersByPage(customerDTO));
    }
}
